package com.haifeng.lyw.jinganghc.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import com.haifeng.lyw.jinganghc.R;
import com.haifeng.lyw.jinganghc.bluetooth.deviceActivity;
import com.haifeng.lyw.jinganghc.dao.UserDao;
import com.haifeng.lyw.jinganghc.dao.UserInfo;
import com.haifeng.lyw.jinganghc.utils.AppConstants;
import com.haifeng.lyw.jinganghc.utils.PermissionsChecker;
import com.haifeng.lyw.jinganghc.utils.SpUtils;


public class SplashActivity extends Activity {
    private PermissionsChecker mChecker;
    private boolean isRequireCheck; // 是否需要系统权限检测
    public static final int PERMISSIONS_GRANTED = 0; // 权限授权
    public static final int PERMISSIONS_DENIED = 1; // 权限拒绝



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mChecker = new PermissionsChecker(this);
        isRequireCheck = true;
        // 判断是否是第一次开启应用
        boolean isFirstOpen = SpUtils.getBoolean(this, AppConstants.FIRST_OPEN);
        // 如果是第一次启动，则先进入功能引导页
        if (!isFirstOpen) {
            Intent intent = new Intent(this, WelcomeGuideActivity.class);
            startActivity(intent);
            addData();
            finish();
            return;
        }

        // 如果不是第一次启动app，则正常显示启动屏
        setContentView(R.layout.activity_splash);

        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                enterHomeActivity();
            }
        }, 2000);
    }

    private void enterHomeActivity() {
        Intent intent = new Intent(this, deviceActivity.class);
        startActivity(intent);
        finish();
    }

    @Override
    protected void onResume() {
        super.onResume();

    }


    /**
     * 添加数据
     */
    private void addData() {
        String[] actionname = getResources().getStringArray(R.array.action_name);
        String[] actionorder = getResources().getStringArray(R.array.action_order);
        for (int i = 0; i <actionname.length; i++) {
            UserInfo userInfo = new UserInfo();
            userInfo.setType("格斗");//wrestle格斗
            userInfo.setName("格斗键"+(i+1));
            userInfo.setAction(actionname[i]);
            userInfo.setAction_order(actionorder[i]);
            UserDao.getInstance().insertUserData(userInfo);
//            UserDao.getInstance().queryUserByParams(userInfo.getQuestion(),"哈哈");
        }
        for (int i = 0; i <actionname.length; i++) {
            UserInfo userInfo = new UserInfo();
            userInfo.setType("踢球");//wrestle格斗
            userInfo.setName("踢球键"+(i+1));
            userInfo.setAction(actionname[i]);
            userInfo.setAction_order(actionorder[i]);
            UserDao.getInstance().insertUserData(userInfo);
//            UserDao.getInstance().queryUserByParams(userInfo.getQuestion(),"哈哈");
        }
    }

}